﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;

namespace BeatEmUp
{
    class Map : DrawableGameComponent,IMap
    {
        List<GameField> gameFields;
        int activeGameField;
        Player player;
        public Map(Game game):
            base(game)
        {
            
            gameFields = new List<GameField>();
            gameFields.Add(new GameField(game, new Rectangle(0, 150, ((Game)this.Game).graphics.GraphicsDevice.Viewport.Width, ((Game)this.Game).graphics.GraphicsDevice.Viewport.Height - 250)));
            activeGameField = 0;
            MovementBoundaries.gameField = gameFields[activeGameField].GetFieldSize();
            player = new Player(new Rectangle(0,(gameFields[activeGameField].GetFieldSize().Y + gameFields[activeGameField].GetFieldSize().Height)/2,100,100),
                game.Content.Load<Texture2D>("Sprites/Player 1/Idle"));
        }

        public override void Initialize()
        {
            this.Game.Components.Add(gameFields[activeGameField]);
            base.Initialize();
        }

        protected override void LoadContent()
        {
            base.LoadContent();
        }

        public GameField GetActiveGameField()
        {
            return gameFields[activeGameField];
        }

        public override void Update(GameTime gameTime)
        {
            player.UpdatePlayerPosition(Keyboard.GetState(), GamePad.GetState(PlayerIndex.One));
            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            SpriteBatch sb = ((Game)this.Game).SpriteBatch;
            sb.Begin();
            sb.Draw(player.PlayerTexture, player.GetPlayerPosition(), Color.White);
            sb.End();
            base.Draw(gameTime);
        }
    }
}
